#location assignment for supply depots + protoss nexus

import re

TOTAL_DEPOTS = 60 #number of all expos on map

TOTAL_NEXUS = 6 #number of all nexuses on map

N_COUNT  = 10 #number of garrison units spawned

D_COUNT = 5 #number of garrison units spawned

UNIT = "Jim Raynor (Marine)" #the garrison unit


w = open('depot_init_trig.txt', 'r')
r = open('nexus_init_trig.txt', 'r')
u = open('nexus_attack_trig.txt', 'r')
v = open('depot_attack_trig.txt', 'r')

depot_template = w.read()
nexus_template = r.read()
n_attack_template = u.read()
d_attack_template = v.read()

w.close()
r.close()
u.close()
v.close()


dcs = ['Alan Turret', 'Cantina', 'Cave', 'Cave-in', 'Disruption Field', 'Duke Turret type 1',
       'Duke Turret type 2', 'Goliath Turret', 'Independent Command Center', 'Independent Starport', 'Jump Gate',
       'Khaydarin Crystal Formation', 'Kyadarin Crystal Formation', 'Mining Platform',
       'Nuclear Missile', 'Protoss Marker', 'Protoss Unused type 1', 'Protoss Unused type 2', 'Psi Emitter',
       'Right Pit Door', 'Right Upper Level Door', 'Right Wall Flame Trap', 'Right Wall Missile Trap',
       'Ruins', 'Scanner Sweep', 'Start Location', 'Tank Turret type 1', 'Tank Turret type 2', 'Terran Beacon', 'Protoss Beacon',
       'Terran Flag Beacon', 'Protoss Flag Beacon', 'Terran Marker', 'Protoss Observatory', 'Unused type 1',
       'Unused type 2', 'Unused Terran Bldg type 1', 'Unused Terran Bldg type 2', 'Unused Zerg Bldg', 'Unused Zerg Bldg 5',
       'Vespene Geyser', 'Zerg Beacon', 'Zerg Flag Beacon', 'Dark Swarm', 'Data Disc', 'Cocoon', 'Zerg Egg', 'Flag',
       'Floor Gun Trap', 'Floor Hatch (UNUSED)', 'Floor Missile Trap', 'Left Pit Door', 'Left Upper Level Door',
       'Left Wall Flame Trap', 'Left Wall Missile Trap', 'Mineral Field (Type 1)', 'Mineral Field (Type 2)', 'Mineral Field (Type 3)',
       'Vespene Orb (Protoss Type 1)', 'Vespene Orb (Protoss Type 2)', 'Vespene Sac (Zerg Type 1)',
       'Vespene Sac (Zerg Type 2)', 'Vespene Tank (Terran Type 1)', 'Vespene Tank (Terran Type 2)', 'Ursadon (Ice World)',
        'Bengalaas (Jungle)']

#regex
GET_DEPOT = re.compile(r'(?<=Depot)[0-9]+')
GET_NEXUS = re.compile(r'(?<=Nexus)[0-9]+')
GET_COUNT = re.compile(r'(?<=, )(10|5)(?=, )')
GET_UNIT = re.compile(r'Jim Raynor (Marine)')
GET_DC = re.compile(r'Alan Turret')

def depot_init_macro():
    w = open('depot_init_trigs.txt', 'w')
    for x in range(0, TOTAL_DEPOTS):
        new_str = GET_DEPOT.sub(str(x + 1), depot_template)
        print>>w, new_str
    w.close()

def nexus_init_macro():
    w = open('nexus_init_trigs.txt', 'w')
    for x in range(0, TOTAL_NEXUS):
        new_str = GET_NEXUS.sub(str(x + 1), nexus_template)
        print>>w, new_str
    w.close()
        
        
def nexus_attack_macro():
    w = open('nexus_attack_trigs.txt', 'w')
    total = 0
    for x in range(0, TOTAL_NEXUS):
        new_str = GET_NEXUS.sub(str(x + 1), n_attack_template)
        new_str = GET_COUNT.sub(str(N_COUNT), new_str)
        new_str = GET_UNIT.sub(UNIT, new_str)
        new_str = GET_DC.sub(dcs[total], new_str)
        total += 1
        print>>w, new_str
    w.close()


def depot_attack_macro():
    w = open('depot_attack_trigs.txt', 'w')
    total = TOTAL_NEXUS
    for x in range(0, TOTAL_DEPOTS):
        new_str = GET_DEPOT.sub(str(x + 1), d_attack_template)
        new_str = GET_COUNT.sub(str(D_COUNT), new_str)
        new_str = GET_UNIT.sub(UNIT, new_str)
        new_str = GET_DC.sub(dcs[total], new_str)
        total += 1
        print>>w, new_str
    w.close()

